﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
		<div class="btns-container"></div>
		<div class="condition">
			<label>搜索关键字</label>
			<input id="keys" class="form-control input-w170" placeholder="货架编号或名称" />
			<label>季节</label>
			<select id="search-season" class="form-control input-w170">
				<option value="">所有</option>
			</select>
			<label>年份</label>
			<select id="search-year" class="form-control input-w160">
				<option value="">所有</option>
			</select>
			<label>是否有效</label>
            <select id="isRemove" class="form-control input-w160">
				<option value="-1">全部</option>
				<option value="0">有效</option>
				<option value="1">无效</option>
			</select>
		</div>
		
		<div class="right-content-box">
			<div class="ibox-content">
				<table class="footable table table-stripped">
					<thead></thead>
					<tbody id="pageList"></tbody>
				</table>
			</div>
		</div>
		
		<div class="pageControl"></div>
		
	</div>
</div>

<div class="detail-box">
	<div class="d-b-header">
		<i class="fa fa-times close-detail-box"></i>
	</div>
	<div class="d-b-content">
		<dl>
			<dt>
				<div class="pic"></div>
				<p class="d-name"></p>
			</dt>
			<dd>
				<table class="d-b-table" cellpadding="0" cellspacing="0">
					<thead></thead>
					<tbody class="d-b-list"></tbody>
				</table>
			</dd>
		</dl>
	</div>
</div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
<script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
<script src="../assets/js/framework.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script type="application/javascript">
$(document).ready(function(){
	//模块ID
	var ModuleID = Y.getUrlParam("ModuleID");    
    //用于记录页数
    var page = 1;
	//用于记录每页多少条记录
	var size = 10;
	//用于记录选中项的id
	var sdid = 0;
	//用于记录各项信息
	var pageList = [];
	
	commonUtil.loadBtnList(ModuleID,function(){
		$('#editBtn').attr('disabled','disabled');
		$('#deleteBtn').attr('disabled','disabled');
		$('#copyBtn').attr('disabled','disabled');
		rScroll();
	});
	
	//绑定年份
    commonUtil.bindDict({DictValue: 'year'},['#search-year']);
            
    //绑定季节
    commonUtil.bindDict({DictValue: 'season'},['#search-season']);
	
	//加载信息列表
    var loadList = function(){
    	if($('.footable thead').children().size() == 0)
			tableControl.initThead2('.footable',['图片','年份','季节','货架编号','货架名称','A级陈列标准SKC','B级陈列标准SKC','C级陈列标准SKC','是否有效']);
    	    	
    	$('.detail-box').fadeOut();
    	pageControl.init('DisplayShelf','GetList',{
			Keys: $('#keys').val(),
            Year: $('#search-year').val(),
            Season: $('#search-season').val(),
            IsRemove: $('#isRemove').val(),
            Page: page,
//          Size: size,
			alwaysCallBack:function(){
				sdid = 0;
		    	$('#editBtn').attr('disabled','disabled');
		    	$('#deleteBtn').attr('disabled','disabled');
				$('#copyBtn').attr('disabled','disabled');
			}
		},function(result){
			page = result.page;
			var tBody = [];
			if (!Y.checkNull(result.data)) {
				if (result.data.Items.length > 0){
					result.data.Items.map(function(item,i){	
						var tempTr = {
							trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
							children: [
								{tdText: item.SDID, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'hide'},
								{tdText: '', c:0 , r:0, tdHtml:'<img alt="image" src="'+ item.ImageUrl +'" class="itemPic" />', tdId:'', tdClass:''},
								{tdText: (item.Year || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.Season || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.GSCode || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.GSName || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.ASKC || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.BSKC || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.CSKC || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
								{tdText: (item.IsRemove ? ' 无效 ' : ' 有效 '), c:0 , r:0, tdHtml: ('<i class="fa fa-'+ (!item.IsRemove ? 'check text-navy' : 'times text-danger') +'"></i>'), tdId:'', tdClass:''},
							]
						};
						tBody.push(tempTr);
					})
				}
				rScroll();
				pageList = [];
				pageList = result.data.Items;
			}
			tableControl.initTbody('.footable',(tBody.length > 0 ? tBody : null),8,null);
		});
    }
    loadList();
    
    //选中项
    $('#pageList').on('click','tr',function(){
    	var temp = parseInt($(this).find('td:first').text());
    	if(isNaN(temp))
    		return false;

//  	if(sdid == temp)
//  		return false;
    	sdid = temp;
    	$('#editBtn').removeAttr('disabled');
    	$('#deleteBtn').removeAttr('disabled');
		$('#copyBtn').removeAttr('disabled');

    	$('#pageList tr').removeClass('check');
    	$(this).addClass('check');
    	
    	//处理详情框信息
    	if($('.d-b-table thead').children().size() == 0){
	    	tableControl.initThead('.d-b-table',[
				{trClass:'', children:[
					{tdText:'系列', c:0 , r:2, tdHtml:'', tdId:'', tdClass:''},
					{tdText:'商品层', c:0 , r:2, tdHtml:'', tdId:'', tdClass:''},
					{tdText:'品类', c:0 , r:2, tdHtml:'', tdId:'', tdClass:''},
					{tdText:'出样件数', c:3 , r:0, tdHtml:'', tdId:'', tdClass:''},
				]},
				{trClass:'', children:[
					{tdText:'最低', c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
					{tdText:'标准', c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
					{tdText:'最高', c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
				]}
			])
	    }
    	
    	var pageItem = pageList[$(this).index()];
    	$('.detail-box .pic').css({'backgroundImage' : 'url('+ pageItem.ImageUrl +')'});
    	$('.detail-box .d-name').text(pageItem.GSName);
    	var tBody = [];
    	if(!Y.checkNull(pageItem.GoodDetails)){
    		if(pageItem.GoodDetails.length > 0){
    			pageItem.GoodDetails.map(function(item,i){
					var tempTr = {
						trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
						children: [
							{tdText: (item.Series || '-'), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.CommodityLayer || '-'), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.Category || '-'), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.Minimum || 0), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.Avgximum || 0), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.Maximum || 0), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
						]
					};
					tBody.push(tempTr);
				})
    		}
    	}
    	tableControl.initTbody('.d-b-table',(tBody.length > 0 ? tBody : null),5,null);
    	//弹出详情框
    	$('.detail-box').fadeIn();
    })
    
    //查询按钮
    $('.btns-container').on('click','#btn-search',function(){
    	page = 1;
    	loadList();
    });
    
	$('#uploadFile').change(function(){
		$('#showFile').val($(this).val());
	});
	
	//添加按钮
	$('.btns-container').on('click','#addBtn',function(){
		var addDisplayTab = $('#addDisplayInfoTab span',window.parent.document);
		addDisplayTab.parent().attr('href','shelf/AddDisplayInfo.aspx');
		addDisplayTab.click();
	});
	
	//编辑按钮
	$('.btns-container').on('click','#editBtn',function(){
		//先关闭已开的编辑窗口
		commonUtil.closeRepeatWindow('编辑货架陈列信息');
  	
		var editDisplayInfoTab = $('#editDisplayInfoTab span',window.parent.document);
		editDisplayInfoTab.text('编辑货架陈列信息');
		editDisplayInfoTab.parent().attr('href','shelf/EditDisplayInfo.aspx?id='+sdid);
		editDisplayInfoTab.click();
	});
	
	//复制按钮
	$('.btns-container').on('click','#copyBtn',function(){
		//先关闭已开的复制窗口
		commonUtil.closeRepeatWindow('复制货架陈列信息');
		
		var editDisplayInfoTab = $('#editDisplayInfoTab span',window.parent.document);
		editDisplayInfoTab.text('复制货架陈列信息');
		editDisplayInfoTab.parent().attr('href','shelf/EditDisplayInfo.aspx?id='+ sdid +'&isCopy=true');
		editDisplayInfoTab.click();
	});
    
    //删除按钮
    $('.btns-container').on('click','#deleteBtn',function(){
    	swal({
			title: "确定要删除吗？",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			closeOnConfirm: false
		}, function(){
			Y.API2('DisplayShelf','Remove',{
				SDID: sdid
			},function(data){
				if(data.Success == false){
					swal(data.Message, '', 'error');
				}else{
					swal('删除成功', '', 'success');
					loadList();
				}
			})
		});
	});
    
    
    //批量添加任务
	$(".btns-container").on("click",'#importBtn',function () {
	    $.ImportExcelTemplate({
	        filetype: ['Shelfdisplay','Shelfdisplaydetail'], 
	        filename: [
	        	{name: '货架陈列信息', state: null},
	        	{name: '货架陈列明细信息', state: 'hasInfo'}
	        ],
	        action: 'ImportTemplate', after: function () {
                //回调方法
                page = 1;
	            loadList();
	        }
	    });
	});
	
	//点击关闭详情框按钮
	$('.close-detail-box').click(function(){
		$('.detail-box').fadeOut();
	});
})
</script>
</asp:Content>

